import Vue from 'vue'
import Vuex from 'vuex'
// 引入封装好的模块
import menu from "./modules/menu"
import role from './modules/role'
import user from './modules/user'
import cate from './modules/cate'
import specs from './modules/specs'
import manage from "./modules/manage"
import member from './modules/member'
import banner from './modules/banner'
import seck from './modules/seck'

Vue.use(Vuex)
export default new Vuex.Store({
  state: {
    userinfo: sessionStorage.getItem("userinfo") ? JSON.parse(sessionStorage.getItem("userinfo")) : null
  },
  getters: {
    getUser(state) {
      return state.userinfo
    }
  },
  mutations: {
    REQ_USERINFO(state, payload) {
      if (payload) {
        state.userinfo = payload
        //判断如果payload有值的话进行存储
        sessionStorage.setItem("userinfo", JSON.stringify(payload))

      }


    }

  },
  actions: {
    changeUser({ commit }, payload) {
      commit("REQ_USERINFO", payload)

    }
  },
  modules: {
    menu,
    role,
    user,
    cate,
    specs,
    manage,
    member,
    banner,
    seck


  }
})
